package com.exam.service.impls;

import com.exam.domain.Grade;
import com.exam.domain.Question;
import com.exam.domain.Strategies;
import com.exam.mapper.GradeMapper;
import com.exam.mapper.QuestionMapper;
import com.exam.mapper.StrategiesMapper;
import com.exam.service.interfaces.StudentExamService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by jly on 2017/3/3.
 */
@Service("studentExamService")
public class StudentExamServiceImpl implements StudentExamService {
    @Resource
    private QuestionMapper questionMapper;
    @Resource
    private GradeMapper gradeMapper;
    @Resource
    private StrategiesMapper strategiesMapper;

    @Override
    public Integer queryQCount(Integer fieldid, int typeId,int level) {
        return questionMapper.queryQCount(fieldid,typeId,level);
    }

    /**
     * 随机试题组卷
     *
     * @return: 试题列表
     * @since: 2017-3-6
     * @author: jly
     * */
    @Override
    public List<Question> studentExam(Integer fieldid,int count,String level) {
        return questionMapper.studentExam(fieldid,count,level);
    }

    /**
     * 随机试题组卷
     *
     * @return: 试题列表
     * @since: 2017-3-6
     * @author: jly
     * */
    @Override
    public List<Question> studentExam2(Integer fieldid,int count,String level) {
        return questionMapper.studentExam2(fieldid,count,level);
    }

    @Override
    public List<Question> studentExam3(Integer fieldid, int count,String level) {
        return questionMapper.studentExam3(fieldid,count,level);
    }

    @Override
    public List<Question> studentExam4(Integer fieldid,int typeId,int count,String level) {
        return questionMapper.studentExam4(fieldid,typeId,count,level);
    }

    /**
     * 根据试题id得到试题正确答案
     *
     * @return: 试题正确答案
     * @since: 2017-3-7
     * @author: jly
     * @param questionid
     * */
    @Override
    public String queryAnswer(Integer questionid) {
        return questionMapper.queryAnswer(questionid);
    }

    /**
     * 向成绩表插入学生成绩
     *
     * @return true-成功,false-失败
     * @since 2017-3-7
     * @author jly
     * @param userid 当前用户id, field 选择科目id, rank 等级判定, grade 分数
     * @param nowtime
     * @param strattime  */
    @Override
    public boolean addGrade(Long userid, Integer field, int rank, int grade, String nowtime, String strattime) {
        return questionMapper.addGrade(userid,field,rank,grade,nowtime,strattime);
    }

    /**
     * 加载学生成绩列表（登录角色为学生）
     *
     * @return Grade类型的成绩详细信息
     * @since 2017-3-8
     * @author jly
     * */
    @Override
    public List<Grade> studentGrades(Long userId) {
        return gradeMapper.studentGrades(userId);
    }

    /**
     * 查询主观题种类个数
     *
     * @param fieldid 科目类别id
     * @since 2017-3-17
     * @author jly
     * */
    @Override
    public List<Strategies> queryZGTcount(Integer fieldid) {
        return strategiesMapper.queryZGTcount(fieldid);
    }

    /**
     * 查询成绩表最大id
     *
     * @since 2017-3-20
     * @author jly
     * */
    @Override
    public int queryMaxgradeId() {
        return questionMapper.queryMaxgradeId();
    }

    /**
     * 向老师的判分表插入数据
     *
     * @since 2017-3-20
     * @author jly
     * */
    @Override
    public boolean addteachergrade(Integer questionid, int maxgradeId, int grade, String nowtime, String answer) {
        return questionMapper.addteachergrade(questionid,maxgradeId,grade,nowtime,answer);
    }
}
